class ReactionsController < ApplicationController
  # ==========================================
  # Filters!
  # ==========================================
  # ony logged in users can do these axions
  before_filter :authorize, :only => :destroy
  
  #suppress layout for this controller
  #layout nil
  
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }
  
  # ==========================================
  # Local Variables!
  # ==========================================
  

  # ==========================================
  # Shadow Methods for Ajax Calls!
  # ==========================================
  
  def scroll_last_added
    @reaction_pages, @reactions = paginate :reactions, 
      :order => "created_at DESC", :per_page => 1
    # suppress layout
    render :layout => false
  end
  
  # ==========================================
  # Public Methods!
  # ==========================================

  def index
    list
    render :action => 'list'
  end
  
  def list
    @reaction_pages, @reactions = paginate :reactions, 
        :order => "created_at DESC", :per_page => 10
  end
  
  def show
    @reaction = Reaction.find(params[:id])
  end
  
  def new
    @reaction = Reaction.new
  end
  
  def create
    logger.info(params)
    @reaction = Reaction.new(params[:reaction])
    if !@reaction.save
      render :action => :new
    else
      list
      render :action => :list
    end
  end
  
  def edit
    @reaction = Reaction.find(params[:id])
  end
  
  # ==========================================
  # Private Methods!
  # ==========================================
  
end
